<?php
// ------------------------------------------------------------------------------------
// Bestand:       Admin controller
// Versie:        1.1
// Projekt:       Cursus MasterClass van Eduvision
// Datum:         24-06-2008
// Auteur(s):     Ronald Obbens
// Email(s):      r.lagendijk@hccnet.nl/ronaldobbens@gmail.com
// Revisie(s):	  1.1 -> extends controller
//
// Beschrijving:  frontpage for the admin
// ------------------------------------------------------------------------------------
//
require_once('Controller.php');
require_once('DataBase.php');
require_once('User.php');
require_once('Question.php');

class adminController extends Controller
{
	public function index()
	{
		$aQuestionsNotAnswerred = array();
		$aLastUsers = array();
		
		$DB = new Database();
		$output = $DB->runDirectQuery("SELECT * FROM Question WHERE answer IS NULL");
		
		foreach($output->getData() as $question)
		{
			$aQuestionsNotAnswerred[] = '<a href="'.DOMAIN_URL.'/admin/answer/'. $question['id'] . '">' . $question['question'] . '</a>';
		}
		
		unset($output);
		
		$output = $DB->runDirectQuery("SELECT * FROM Users LIMIT 10");
		
		foreach($output->getData() as $user)
		{
			$aLastUsers[] = $user['realname'];
		}
		
		unset($output);
	
		parent::assign('stilltoanswer',$aQuestionsNotAnswerred);
		parent::assign('lastten', $aLastUsers);
		parent::render('adminportal.tpl');
	}
	
	/**
	 * begin answer procedure question
	 *
	 * @param unknown_type $p_iQuestionID
	 */
	public function answer($p_iQuestionID)
	{
		$question = new Question();
		$question->setByParentId($p_iQuestionID);

		parent::assign('question',$question->getQuestion());
		parent::assign('questionid',$question->getId());
		parent::render('answerquestion.tpl');
	}
	
	/**
	 * update answerred question in the database
	 *
	 */
	public function updatequestion($p_iQuestionID)
	{
		$p_sAnswer = $_POST['answer'];
		$p_sKeywords = $_POST['keywords'];
				
		$question = new Question();
		$question->setByParentId($p_iQuestionID);
		
		$question->setAnswer($p_sAnswer);
		$question->setKeywords($p_sKeywords);
		$question->setAnswerDate(time());
		//$question->setAnswerrer($_SESSION['user']->getId());
		
		$this->index();
	}
}
?>